$(function() {
	
	
	//显示用户
	$.getJSON('../../UserInfoPage',{
		pageShowNumber:10,
		currentPage:1
	},function(data,status){
		
		$('tbody').empty();
		for(var i=0;i<data.length;i++){
			
			$('tbody').append('<tr><td>'+data[i].VIP_ID+'</td><td>'+data[i].VIP_NAME+'</td><td>'+data[i].VIP_ALLMONEY+'</td><td>'+data[i].VIP_REGISTDATE+'</td></tr>');
			
		}
		
	});
	
	showChart();
	showRecentForm();
	showOther();
	
});



function showChart(){
	
	

	
	var data_morris = '[';
	var data_donut = '[';
	var data_bar = '[';
	
	$.getJSON('../../StatsDeal',{
		flag:4
	},function(data,status){
		
		if(status){
			
			//生成datas数据
			
			var allIn = 0;
			var allOut = 0;
			
			$('tbody').empty();
			
			for(var i = 0; i < data.length; i ++){
				
				var info = data[i];
				
				allIn += parseInt(info.INMONEY);
				allOut += parseInt(info.OUTMONEY);
					
				if(i == data.length-1){
					data_morris += '{period:\''+info.DATES+'\',outs:'+parseInt(info.OUTMONEY)+',ins:'+info.INMONEY+'}]';
				}else{
					data_morris += '{period:\''+info.DATES+'\',outs:'+parseInt(info.OUTMONEY)+',ins:'+info.INMONEY+'},';
				}
		    

				
				
			}
			
			data_donut += '{label: "总收入",value: '+parseInt(allIn)+'}, {label: "总支出",value: '+parseInt(allOut)+'}, {label: "总利润",value: '+(parseInt(allIn)-parseInt(allOut))+' }]';
			
			
			$('.chart-1').append('<div id="morris-area-chart"></div>');
			
			//折线
			var area = Morris.Area({
			    element: 'morris-area-chart',
			    data: eval(data_morris),
			    xkey: 'period',
			    ykeys: ['ins', 'outs'],
			    labels: ['收入', '支出'],
			    pointSize: 2,
			    hideHover: 'auto',
			    resize: true
			});
			
			


			$('.chart-3').append('<div id="morris-donut-chart"></div>');
			try{
			//扇形图
			 Morris.Donut({
			        element: 'morris-donut-chart',
			        data: eval(data_donut),
			        resize: true
			    });
			}catch(e){
				console.error(e);
			}
			 	

		}
		
	})
	
	
	//显示最近下单
	
	
	
	
}


function showRecentForm(){
	$.getJSON('../../StatsDeal',{
		flag:5
	},function(data,status){
		$('.list-group').empty();
		for(var i = 0;i < data.length;i ++){
			$('.list-group').append('<a href="#" class="list-group-item"> <i class="fa fa-twitter fa-fw"></i> '+data[i].NAMES+' <span class="pull-right text-muted small"><em>'+data[i].DATES+'</em> </span>');
		}
	});
}

function showOther(){
	$.getJSON('../../StatsDeal',{
		flag:6
	},function(data,status){
		$('.huge-1').html(data[0].FCOUNT);
		$('.huge-2').html(data[0].PCOUNT);
		$('.huge-3').html(data[0].OLNUM);
	});
}


